package com.item.read.store;


import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.ComponentManager;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.components.State;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.util.xmlb.XmlSerializerUtil;
import com.sun.istack.NotNull;
import com.sun.istack.Nullable;

@State(name = "SettingConfig",storages = {@com.intellij.openapi.components.Storage(value = "learnEn-config.xml",
        roamingType = com.intellij.openapi.components.RoamingType.DISABLED)})
public class SettingState implements PersistentStateComponent<SettingState> {
    private SettingConfig initConfig;

    public SettingState() {

    }

    @Nullable
    public static SettingState getInstance() {
        return (SettingState) ApplicationManager.getApplication().getService(SettingState.class);
    }

    @Nullable
    @Override
    public SettingState getState() {
        return this;
    }

    @Override
    public void loadState(@NotNull SettingState settingConfig) {
        if (settingConfig == null) {
            return;
        }
        XmlSerializerUtil.copyBean(settingConfig, this);
    }


    public SettingConfig getConfig() {
        if (initConfig == null) {
            initConfig = new SettingConfig();
        }
        return initConfig;
    }


    public void setConfig(SettingConfig config) {
        initConfig = config;
    }
}

